This section provides a quick and high-level overview of using T-SQL syntax to create databases and users.
You've walked through how to
create and manage databases using the SQL Azure Portal, but now let's
use SQL Server Management Studio (SSMS) to create and manage a database.
This book uses SQL Server 2008 R2 throughout for the examples.
Fire up SQL Server 2008 R2,
and enter the FQDN of the database server name in the "Server name" box
when the Connect to Server dialog appears (see Figure 1). Enter the administrator login name and password, and click Connect. You're now connected to SQL Azure.
At this juncture, the only
database available to you is the master database, unless you've created
databases via the SQL Azure Portal. Let's spend a few minutes discussing
how to create databases and other objects using T-SQL.
1. Databases
When you create databases in a non-Azure environment, you have to know and specify a lot in the CREATE
statement. For example, you must provide the path and physical object
names of the database and log files, as well as the database size and
optionally the maximum size and file growth. A CREATE DATABASE statement in a non-Azure environment might look like the following:
CREATE DATABASE [MyDatabase] ON PRIMARY
( NAME = N'MyDatabase', FILENAME = N'C:\Program Files\Microsoft SQL
Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MyDatabase.mdf' , SIZE = 32768KB , MAXSIZE =
UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'MyDatabase_log', FILENAME = N'C:\Program Files\Microsoft SQL
Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\MyDatabase_log.ldf' , SIZE = 92864KB , MAXSIZE = 2048GB
, FILEGROWTH = 10%)
GO
As you've learned in the past
few chapters, with Azure you don't have to worry about hardware and
where objects are located and how hardware is provisioned, which makes
statements such CREATE DATABASE much simpler.
CREATE DATABASE MyDatabase
You can optionally supply two parameters with the CREATE DATABASE statement: MAXSIZE, which specifies the maximum size of the database; and EDITION, which specifies the edition of the database (Web or Business). Here's an example:
CREATE DATABASE MyDatabase (MAXSIZE= 10 GB, EDITION= 'Business')
In the current release of
SQL Azure, two database sizes are available for the Web edition: 1GB and
5GB. For the Business edition, available sizes range from 10GB to 50GB,
in increments of 10GB. If MAXSIZE is set to a value of 1GB or 5GB and EDITION isn't specified, the database edition is automatically set to Web. If MAXSIZE is set to a value between 10BG and 50GB and EDITION isn't specified, the database edition is automatically set to Business. If neither MAXSIZE nor EDITION is specified, a Web database of 1GB is created.
SQL Azure doesn't
support additional arguments that you're used to using when working with
SQL in a local environment. For example, SQL Azure doesn't support
parameters that relate to working with physical files, such as filespec and filegroup. You also can't attach or detach a database.